<?php
namespace app\index\controller;

use think\Db;
use think\Config;
use think\Session;
use app\index\model\JokeArticle;

class Index extends _Abstract
{
    public function _initialize()
    {
		parent::_initialize();
    }
	
    public function index()
    {
		//$all = Db::query("SELECT * FROM bt_hash WHERE sync = ? LIMIT 0,10", [0]);
    	$all = JokeArticle::findAll(['status' => 1], 'content', 10);
    	return $this->fetch('index/home', ['all' => $all]);
    }
	
	public function add()
	{
		if ('POST' == $this->request->method()) {
			$content = trim($this->request->post('content'));
			if ($content) {
				$data = ['content' => $content, 'created' => time(), 'status' => 1];
				if ($this->auth) {
					$data['user_id'] = $this->auth->id;
				}
				$id = JokeArticle::insertGetId($data);
			}
		}
		return $this->view->fetch();
	}
	
	
	
	public function accounts()
	{
		$action = $this->request->param('name');
		$location = null;
		switch ($action) {
			case 'signin':
				$location = "http://urlnk.com/accounts/signin?service=http://torrent.filemule.top/accounts/sso";
				break;
			case 'logout':
				unset($_SESSION['auth']);
				$location = "/";
				break;
			case 'sso':
				$location = $this->request->get('continue', '/');
				break;
		}
		
		if (null !== $location) {
			$this->redirect($location);
		}
		
	}
	
	public function joke()
	{
		$id = $this->request->param('id');
		$row = JokeArticle::find($id)->toArray();
		print_r($row);
	}
	
	public function hello()
	{
		print_r($this->request->param());
	}
}
